﻿using FluentExport.CSVExport.Interfaces;

namespace FluentExport.CSVExport
{
    public class CSVSimpleSource : ICSVSimpleSource
    {
        #region Members

        private readonly ICSVExportHelper _csvExportHelper;
   
        #endregion

        #region Properties

        public string PropertyName
        {
            get;
            set;
        }

        #endregion

        #region Constructors

        public CSVSimpleSource(ICSVExportHelper csvExportHelper)
        {
            _csvExportHelper = csvExportHelper;
        }

        #endregion

        #region Methods

        public string GetValue(object data)
        {
            var propertyInfo = data.GetType().GetProperty(PropertyName);
            var value = propertyInfo.GetValue(data, null);

            return _csvExportHelper.FormatValue(value);
        }

        #endregion

    }
}
